﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using RibbonEditor.AppCode;

namespace RibbonEditor.CommandUIDefinitionClasses
{
    public class Button : ICommandUIDefinition, IControlsChild, IXmlBuildable
    {
        public string Alt { get; set; }
        public string Command { get; set; }
        public Enumerations.CommandType CommandType { get; set; }
        public string CommandValueId { get; set; }
        public string Description { get; set; }
        public string Id { get; set; }
        public string Image16by16 { get; set; }
        public string Image16by16Class { get; set; }
        public int? Image16by16Left { get; set; }
        public int? Image16by16Top { get; set; }
        public string Image32by32 { get; set; }
        public string Image32by32Class { get; set; }
        public int? Image32by32Left { get; set; }
        public int? Image32by32Top { get; set; }
        public string LabelCss { get; set; }
        public string LabelText { get; set; }
        public string MenuItemId { get; set; }
        public int? Sequence { get; set; }
        public string TemplateAlias { get; set; }
        public string ToolTipDescription { get; set; }
        public string ToolTipHelpKeyWord { get; set; }
        public string ToolTipImage32by32 { get; set; }
        public string ToolTipImage32by32Class { get; set; }
        public int? ToolTipImage32by32Left { get; set; }
        public int? ToolTipImage32by32Top { get; set; }
        public string ToolTipShortcutKey { get; set; }
        public string ToolTipTitle { get; set; }

        public Button()
        {

        }

        public Button(XmlNode node)
        {
            try
            {
                this.Alt = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "Alt", XmlHelper.PropertyType.stringType);
                this.Command = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "Command", XmlHelper.PropertyType.stringType);
                XmlHelper.ExtractXmlAttributeToEnumProperty(node, "CommandType", this.CommandType);
                this.CommandValueId = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "CommandValueId", XmlHelper.PropertyType.stringType);
                this.Description = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "Description", XmlHelper.PropertyType.stringType);
                this.Id = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "Id", XmlHelper.PropertyType.stringType);
                this.Image16by16 = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "Image16by16", XmlHelper.PropertyType.stringType);
                this.Image16by16Class = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "Image16by16Class", XmlHelper.PropertyType.stringType);
                this.Image16by16Left = (int?)XmlHelper.ExtractXmlAttributeToProperty2(node, "Image16by16Left", XmlHelper.PropertyType.integerType);
                this.Image16by16Top = (int?)XmlHelper.ExtractXmlAttributeToProperty2(node, "Image16by16Top", XmlHelper.PropertyType.integerType);
                this.Image32by32 = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "Image32by32", XmlHelper.PropertyType.stringType);
                this.Image32by32Class = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "Image32by32Class", XmlHelper.PropertyType.stringType);
                this.Image32by32Left = (int?)XmlHelper.ExtractXmlAttributeToProperty2(node, "Image32by32Left", XmlHelper.PropertyType.integerType);
                this.Image32by32Top = (int?)XmlHelper.ExtractXmlAttributeToProperty2(node, "Image32by32Top", XmlHelper.PropertyType.integerType);
                this.LabelCss = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "LabelCss", XmlHelper.PropertyType.stringType);
                this.LabelText = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "LabelText", XmlHelper.PropertyType.stringType);
                this.MenuItemId = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "MenuItemId", XmlHelper.PropertyType.stringType);
                this.Sequence = (int?)XmlHelper.ExtractXmlAttributeToProperty2(node, "Sequence", XmlHelper.PropertyType.integerType);
                this.TemplateAlias = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "TemplateAlias", XmlHelper.PropertyType.stringType);
                this.ToolTipDescription = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "ToolTipDescription", XmlHelper.PropertyType.stringType);
                this.ToolTipHelpKeyWord = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "ToolTipHelpKeyWord", XmlHelper.PropertyType.stringType);
                this.ToolTipImage32by32 = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "ToolTipImage32by32", XmlHelper.PropertyType.stringType);
                this.ToolTipImage32by32Class = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "ToolTipImage32by32Class", XmlHelper.PropertyType.stringType);
                this.ToolTipImage32by32Left = (int?)XmlHelper.ExtractXmlAttributeToProperty2(node, "ToolTipImage32by32Left", XmlHelper.PropertyType.integerType);
                this.ToolTipImage32by32Top = (int?)XmlHelper.ExtractXmlAttributeToProperty2(node, "ToolTipImage32by32Top", XmlHelper.PropertyType.integerType);
                this.ToolTipShortcutKey = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "ToolTipShortcutKey", XmlHelper.PropertyType.stringType);
                this.ToolTipTitle = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "ToolTipTitle", XmlHelper.PropertyType.stringType);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        #region ICommandUIDefinition Members

        public void AddNode(XmlNode customActionNode)
        {
            try
            {
                XmlNode buttonNode = XmlHelper.AddNode(customActionNode, "Button");
                XmlHelper.AddAttribute(buttonNode, "Alt", this.Alt);
                XmlHelper.AddAttribute(buttonNode, "Command", this.Command);
                XmlHelper.AddAttribute(buttonNode, "CommandType", this.CommandType);
                XmlHelper.AddAttribute(buttonNode, "CommandValueId", this.CommandValueId);
                XmlHelper.AddAttribute(buttonNode, "Description", this.Description);
                XmlHelper.AddAttribute(buttonNode, "Id", this.Id);
                XmlHelper.AddAttribute(buttonNode, "Image16by16", this.Image16by16);
                XmlHelper.AddAttribute(buttonNode, "Image16by16Class", this.Image16by16Class);
                XmlHelper.AddAttribute(buttonNode, "Image16by16Left", this.Image16by16Left);
                XmlHelper.AddAttribute(buttonNode, "Image16by16Top", this.Image16by16Top);
                XmlHelper.AddAttribute(buttonNode, "Image32by32", this.Image32by32);
                XmlHelper.AddAttribute(buttonNode, "Image32by32Class", this.Image32by32Class);
                XmlHelper.AddAttribute(buttonNode, "Image32by32Left", this.Image32by32Left);
                XmlHelper.AddAttribute(buttonNode, "Image32by32Top", this.Image32by32Top);
                XmlHelper.AddAttribute(buttonNode, "LabelCss", this.LabelCss);
                XmlHelper.AddAttribute(buttonNode, "LabelText", this.LabelText);
                XmlHelper.AddAttribute(buttonNode, "MenuItemId", this.MenuItemId);
                XmlHelper.AddAttribute(buttonNode, "Sequence", this.Sequence);
                XmlHelper.AddAttribute(buttonNode, "TemplateAlias", this.TemplateAlias);
                XmlHelper.AddAttribute(buttonNode, "ToolTipDescription", this.ToolTipDescription);
                XmlHelper.AddAttribute(buttonNode, "ToolTipHelpKeyWord", this.ToolTipHelpKeyWord);
                XmlHelper.AddAttribute(buttonNode, "ToolTipImage32by32", this.ToolTipImage32by32);
                XmlHelper.AddAttribute(buttonNode, "ToolTipImage32by32Class", this.ToolTipImage32by32Class);
                XmlHelper.AddAttribute(buttonNode, "ToolTipImage32by32Left", this.ToolTipImage32by32Left);
                XmlHelper.AddAttribute(buttonNode, "ToolTipImage32by32Top", this.ToolTipImage32by32Top);
                XmlHelper.AddAttribute(buttonNode, "ToolTipShortcutKey", this.ToolTipShortcutKey);
                XmlHelper.AddAttribute(buttonNode, "ToolTipTitle", this.ToolTipTitle);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void BuildTreeViewElement(TreeNode parentNode)
        {
            try
            {
                TreeNode buttonNode = new TreeNode("Button");
                buttonNode.Tag = this;
                buttonNode.ContextMenuStrip = ContextMenuStripHelper.BuildUICommandDefContextMenuStrip(buttonNode, null, true);

                parentNode.Nodes.Add(buttonNode);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        #endregion
    }
}
